<#assign ctx="${request.contextPath}" />
<#assign shiro=JspTaglibs["/WEB-INF/taglib/shiro.tld"] />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="${ctx}/static/css/style.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/static/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/static/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/static/js/jquery.ztree.all-3.5.min.js"></script>
</head>

<body>

	<div class="place">
	    <span>位置：</span>
	    <ul class="placeul">
		    <li><a href="#">首页</a></li>
		    <li><a href="#">增加用户</a></li>
	    </ul>
    </div>
    <input type="hidden" name="errorCode" id="errorCode" value="${errorCode}"/>
	<input type="hidden" name="errorMessage" id="errorMessage" value="${errorMessage}"/>
    <div class="formbody">
    	<div class="formtitle"><span>增加信息</span></div>
    	<form action="${ctx}/role/save" method="post" id="form">
		    <ul class="forminfo">
			    <li><label>用户名<b>*</b></label><input name="userName" id="userName" type="text" class="dfinput" value="${user.userName}"/></li>
		    	<input name="ids" id="ids" type="hidden">
		    	<input name="userType" type="hidden" value="SM" />
		    	<li style="overflow:hidden;">
					<label>分配权限<b>*</b></label>
			    	<div class="zTreeDemoBackground" style="float:left;width:345px;">
						<ul id="treeDemo" class="ztree"></ul>
					</div>
			    </li>
			    <li><label>&nbsp;</label><input type="button" class="btn" value="确认保存"/></li>
		    </ul>
		 </form>
    </div>
     <div class="tip">
    		<div class="tiptop"><span>提示信息</span><a></a></div>
	      	<div class="tipinfo">
		        <div class="tipright">
			        <p class="errormMssage"></p>
		        </div>
		    </div>
    </div>
    
    
    <script>
	    $('.btn').click(function(){
	    	var userName = $("#userName").val().replace(/\s/g,"");
	    	if(null == userName || userName == ''){
	    		$(".nameMessage").html("用户名不能为空！");
	    		return false;
	    	}
	    	if(null != userName && userName != ''){
	    		$("#form").submit();
	    	}
		});
    </script>
    <!-- ==============树============== -->
    <SCRIPT type="text/javascript">
	var zNodes = ${sysResourceTreeList};
	var code;
		var setting = {
				view: {
					dblClickExpand: false,
					showLine: true,
		            showIcon: false,
				},
			check: {
				enable: true,
				chkStyle : "checkbox",
				chkboxType : {
					"Y" : "s",
					"N" : "ps"
				},
				
			},
			data: {
				simpleData: {
					enable: true
				}
			},callback: {
				beforeClick : beforeClick,
				onCheck: onCheck
			}
		};

		function setCheck() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			py = $("#py").attr("checked")? "p":"",
			sy = $("#sy").attr("checked")? "s":"",
			pn = $("#pn").attr("checked")? "p":"",
			sn = $("#sn").attr("checked")? "s":"",
			type = { "Y":py + sy, "N":pn + sn};
			zTree.setting.check.chkboxType = type;
			showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
			
		}
		function showCode(str) {
			if (!code) code = $("#code");
			code.empty();
			code.append("<li>"+str+"</li>");
		}
		
		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			setCheck();
			$("#py").bind("change", setCheck);
			$("#sy").bind("change", setCheck);
			$("#pn").bind("change", setCheck);
			$("#sn").bind("change", setCheck);
		});
		
		//--------------
		function beforeClick(treeId, treeNode) {
		    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		    zTree.checkNode(treeNode, !treeNode.checked, null, true);
		    return false;
		}
		function onCheck(e, treeId, treeNode) {
		    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		    var nodes = zTree.getCheckedNodes(true);
		    v = "";
		    for (var i = 0, l = nodes.length; i < l; i++) {
		        if (!nodes[i].isParent) {       //isParent判断是否为父级，也就是是否有下级
		            v += nodes[i].id + ",";   //获取所选节点的名称
		        }
		    }
		    if (v.length > 0)
		        v = v.substring(0, v.length - 1);
		    var ids = $("#ids");
		    ids.attr("value", v);
		}

		
		
	</SCRIPT>
</body>
</html>
